#pragma once
#include <ros/ros.h>
#include <std_msgs/UInt8.h>
#include <ros/time.h>
#include <ros/duration.h>

#include <thread>

// #include "udp_client.h"
#include "tcp_server.h"

class CommApp
{
private:
    /* data */
    
    ros::NodeHandle nh_;

    std::shared_ptr<TcpSerVer> server_;
    ros::Publisher control_cmd_pub_;
    ros::Publisher view_angle_pub_;
    ros::Subscriber motor_limit_status_sub_;
    ros::Subscriber motor_working_status_sub_;


    void CallbackLimitStatus(const std_msgs::UInt8::ConstPtr &msg);
    void CallbackWorkingStatus(const std_msgs::UInt8::ConstPtr &msg);

    uint8_t motor_limit_status_;
    uint8_t motor_working_status_;

    ros::Timer pub_timer_;

    void CallbackPubTimer(const ros::TimerEvent &event);


public:
    CommApp(ros::NodeHandle& nh);
    ~CommApp();
    
    const uint8_t OPEN_CMD = 0b00000001;
    const uint8_t CLOSE_CMD = 0b00000010;
    const uint8_t STOP_CMD = 0b00000000;

    bool Init();

    bool Start();

    bool Stop();    
    
    void LidarControlCmd(uint8_t cmd);

    void ViewAngleSwitch(uint8_t cmd);
};


